package com.keyue.common.utils;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.function.Supplier;

/**
 * @author:
 * @date: 2021/12/21
 */
@Component
public class TransactionHelper {

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public <T> T run(Supplier<T> command) {
        return command.get();
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void run(Runnable command) {
        command.run();
    }


}
